<?php

namespace app\service;

use app\model\FinancialLog;


class FinancialLogService extends BaseService
{


    protected function setModel(): string
    {
        return FinancialLog::class;
    }

    public function flowLog($mid, $amount, $coinId, $frozen, $flowType, $remark = "")
    {

            $memberCoinService = app()->make(MemberCoinService::class);
            $memberCoinInfo = $memberCoinService->getOne(["member_id" => $mid, "coin_id" => $coinId], "account_amount,frozen_amount,id");
            $beforeAmount = 0;
            $beforeFrozen = 0;
            $data["id"] = 0;
            if (!empty($memberCoinInfo)) {
                $beforeAmount = $memberCoinInfo->account_amount;
                $beforeFrozen = $memberCoinInfo->frozen_amount;
                $data["id"] = $memberCoinInfo->id;
            }
            $data["account_amount"] = $beforeAmount + $amount;
            $data["frozen_amount"] = $beforeFrozen + $frozen;
            $data["member_id"] = $mid;
            $data["coin_id"] = $coinId;
            $flowLog["change_amount"] = $amount;
            $flowLog["before_amount"] = $beforeAmount;
            $flowLog["flow_type"] = $flowType;
            $flowLog["remark"] = $remark;
            $flowLog["member_id"] = $mid;
            $flowLog["after_amount"] = $data["account_amount"];
            $flowLog["coin_id"] = $coinId;
            $flowLog["order_sn"] =h_create_order_no("F");
            $memberCoinService->save($data);
            $this->save($flowLog);
            return true;
    }

}